// 导入koa-router模块
const Router = require('koa-router');
// 创建koa-router的实例router
const router = new Router({ prefix: '/api' });
const uploadFileControllers = require('../controllers/file');
// const upload = require("../utils/uploadConfig");

// 定义模型 可以公用 schema $ref
/**
 * @swagger
 * definitions:
 *   fileListVO:
 *     properties:
 *       code:
 *         type: string
 *       success:
 *         type: boolean
 *       data:
 *          type: array
 *          items:
 *             properties:
 *               id:
 *                  type: string
 *                  description: 文件id
 *               name:
 *                   type: string
 *                   description: 文件名称
 *               url:
 *                   type: string
 *                   description: 文件地址
 */

/**
 * @swagger
 * /upload:
 *   post:
 *     description: 上传文件
 *     tags: [文件模块]
 *     summary: 上传文件
 *     consumes:
 *     - multipart/form-data
 *     produces:
 *       - application/json
 *     parameters:
 *       - name: file
 *         in: formData
 *         type: file
 *         description: 文件
 *         required: true
 *     responses:
 *       200:
 *         description: 文件上传成功
 *         schema:
 *           properties:
 *             code:
 *               type: string
 *             success:
 *               type: boolean
 *             data:
 *              type: string
 *              description: "文件上传后的地址"
 *   
 */
router.post('/upload', uploadFileControllers.upload)
/**
 * @swagger
 * /files:
 *   get:
 *     description: 获取所有文件
 *     tags: [文件模块]
 *     summary: 获取所有文件
 *     produces:
 *       - application/json
 *     parameters:
 *       - name: name
 *         description: 文件名称.
 *         in: query
 *         required: false
 *     responses:
 *       200:
 *         description: 操作成功
 *         schema:
 *           type: object
 *           $ref: '#/definitions/fileListVO'
 *   
 */
router.get('/files', uploadFileControllers.getFiles)
/**
 * @swagger
 * /files/delete:
 *   post:
 *     description: 删除文件
 *     tags: [文件模块]
 *     summary: 删除文件
 *     produces:
 *       - application/json
 *     parameters:
 *       - name: ids
 *         description: 文件id.
 *         in: body
 *         required: true
 *     responses:
 *       200:
 *         description: 操作成功
 *   
 */
router.post('/files/delete', uploadFileControllers.deleteFiles)

/**
 * @swagger
 * /files/update:
 *   post:
 *     description: 编辑文件
 *     tags: [文件模块]
 *     summary: 编辑文件
 *     produces:
 *       - application/json
 *     parameters:
 *       - name: ids
 *         description: 文件id.
 *         in: body
 *         required: true
 *     responses:
 *       200:
 *         description: 操作成功
 *   
 */
 router.post('/files/update', uploadFileControllers.updateFiles)

module.exports = router